package com.zh.core;

/**
 * Created by zhaohui on 2019/9/14
 * Description: String测试类
 */
public class StringTest {

    public static void main(String[] args) {
        //1.创建字符串
        String str = "This is a string!";
        System.out.println(str);
        //2.获取字符串的子串
        String subStr = str.substring(0, 3);
        System.out.println(subStr);
        //3.字符串拼接
        //3.1.拼接两个字符串
        String str1 = "Hello ";
        String str2 = "World!";
        String str3 = str1 + str2;
        System.out.println(str3);
        //3.2.拼接多个字符串
        String str4 = String.join("/", "S", "M", "L");
        System.out.println(str4);
        //4.检测字符串是否相等
        String str5 = "hello";
        String str6 = "Hello";
        String str7 = "hello";
        System.out.println(str5 + "=" + str6);
        System.out.println(str5.equals(str6));
        System.out.println(str5 + "=" + str7);
        System.out.println(str5.equals(str7));
        //5.字符串转整数
        String strNum = "1234";
        int num = Integer.parseInt(strNum);
        System.out.println(strNum);
        System.out.println(num);
        //6.字符串转浮点数
        String strNum2 = "1.234";
        double num2 = Double.parseDouble(strNum2);
        System.out.println(strNum2);
        System.out.println(num2);
        //7.获取字符串长度
        String strLen = "This is a string!";
        int len = str.length();
        System.out.println(strLen);
        System.out.println(len);
        //8.获取字符串指定位置的字符
        String strCh = "This is a string!";
        char ch = strCh.charAt(3);
        System.out.println(strCh);
        System.out.println(ch);
        //8.获取指定字符在字符串中首次出现的位置
        String strIndex = "This is a string!";
        int index = strIndex.indexOf('i');
        System.out.println(strIndex);
        System.out.println(index);
        //9.字符串转大写
        //toUpperCase()
        //10.字符串转小写
        //toLowerCase()
        //11.去掉字符串头部尾部的空格
        //trim()
    }

}
